package com.sms.service.impl;

import com.sms.dao.StudentDAO;
import com.sms.dao.TeacherDAO;
import com.sms.dao.UserDAO;
import com.sms.pojo.Student;
import com.sms.pojo.Teacher;
import com.sms.pojo.User;
import com.sms.service.UserService;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDAO userDao;
    @Autowired
    private TeacherDAO teacherDao;
    @Autowired
    private StudentDAO studentDao;

    public void register(User user) {
        //密码加密 加盐为账号 加密次数1024次
        String password = new Sha256Hash(user.getPassword(), user.getUserAccount(), 1024).toBase64();
        user.setPassword(password);
        userDao.addUser(user);
    }

    public User queryUserByName(String userName) {
        return userDao.queryUserByName(userName);
    }

    public Student queryStudentUser(String userId) {
        return studentDao.queryStudentById(userId);
    }

    public Teacher queryTeacherUser(String userId) {
        return teacherDao.queryTeacherById(userId);
    }
}
